Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
4 / 6
CRAP
71.43% covered (warning)
71.43%
10 / 14
Db
0.00% covered (danger)
0.00%
0 / 1
66.67% covered (warning)
66.67%
4 / 6
10.89
71.43% covered (warning)
71.43%
10 / 14
 get_instance
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 __construct
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 setConnection
0.00% covered (danger)
0.00%
0 / 1
3.71
57.14% covered (warning)
57.14%
4 / 7
 query
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getlastId
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
 getInsDb
0.00% covered (danger)
0.00%
0 / 1
2.00
0.00% covered (danger)
0.00%
0 / 1
<?php
/**
 * Created by PhpStorm.
 * User: Viktor
 * Date: 30.06.2019
 * Time: 13:14
 */
namespace App\Models;
class Db
{
    private static $_instance;
    private $ins_db = null;
    public static function get_instance() {
        if(self::$_instance instanceof static) {
            return self::$_instance;
        }
        return self::$_instance = new static();
    }
    private function __construct()
    {
    }
    /**
     * DbDriver constructor.
     */
    public function setConnection($host, $user, $pass, $dbname)
    {
        try {
            $this->ins_db = new \mysqli($host, $user, $pass, $dbname);
            if($this->ins_db->connect_error) {
                throw new DbException("Ошибка соединения : ".$this->ins_db->connect_errno."|".iconv("CP1251","UTF-8",$this->ins_db->connect_error));
            }
            $this->ins_db->query("SET NAMES 'UTF8'");
        }
        catch(DbException $e) {
            exit();
        }
    }
    /**
     * @return null
     */
    public function query($sql)
    {
        return $this->ins_db->query($sql);
    }
    /**
     * @return null
     */
    public function getlastId()
    {
        return $this->ins_db->insert_id;
    }
    /**
     * @return null
     */
    public function getInsDb()
    {
        return $this->ins_db;
    }
}